package com.flw.eslab.service.impl;

import java.io.File;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.flw.eslab.dao.InfoDao;
import com.flw.eslab.dto.PageInfo_Dto;
import com.flw.eslab.model.Info;
import com.flw.eslab.service.InfoManager;



@Service("infoManager")
public class InfoManagerImpl implements InfoManager {
	@Resource
	private InfoDao infoDao;
	public InfoDao getInfoDao() {
		return infoDao;
	}

	public void setInfoDao(InfoDao infoDao) {
		this.infoDao = infoDao;
	}

	@Override
	public boolean add(Info info) {
		if(info.getTitle()==null||info.getTitle().equals(""))
			return false;
		else
			infoDao.save(info);
			return true;
	}

	@Override
	public boolean delete(Info info) {
		if(info.getId()==null){
			info.setId(0);
		}
		//如果数据库中没有这条记
		if(infoDao.findById(Info.class, info.getId())==null)
			return false;
		else
			infoDao.deleteById(Info.class, info.getClass());
			return true;
	}

	@Override
	public boolean modify(Info info) {
		if(info.getId()==null){
			info.setId(0);
		}
		if(infoDao.findById(Info.class, info.getId())==null||info.getTitle()==null||info.getTitle().equals(""))
			return false;
		else
			infoDao.update(info);
			return true;
	}

	@Override
	public File output() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PageInfo_Dto load(PageInfo_Dto pageInfo_Dto) {
		int pageNow=pageInfo_Dto.getPageNow()==null?1:pageInfo_Dto.getPageNow();
		int pageSize=pageInfo_Dto.getPagesize()==null?5:pageInfo_Dto.getPagesize();	
		return infoDao.findByPageInfo(Info.class, pageNow, pageSize, null, null);
	}

	
}
